<?php
class PostData {

	var $id;
	var $Action;
	var $RealtyType;
	var $SettlementRegion;
	var $SettlementCity;
	var $Street;
	var $Area;
	var $Price;
	var $Description;
	var $PersonName;
	var $eMail;
	var $ICQ;
	var $Phone;
	var $PostDate;
	var $errors_count;
	var $LastErrors;
	var $isNew = false; //by default
	
	function PostData() {
		$this->errors_count = 0;
		$this->LastErrors = '';
		$this->PostDate = date("d.m.Y");
	}
		
	function CheckAccuracy(){
		$Errors = new Errors();
		
		$this->Area = str_replace(',', '.', $this->Area);
		$this->Price = str_replace(',', '.', $this->Price);
		
		if(Trim($this->SettlementCity)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("008") . "</td></tr>\n";
		}
		
		if(Trim($this->Area)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("009") . "</td></tr>\n";
		}
		
		if((!ereg("((^[0-9]+$)|(^[0-9]+\.[0-9]+$))", $this->Area)) and (strlen($this->Area)>0)){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("005") . "</td></tr>\n";
		}
		
		if(Trim($this->Price)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("006") . "</td></tr>\n";
		} elseif(!ereg("((^[0-9]+$)|(^[0-9]+\.[0-9]+$))", $this->Price)){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("007") . "</td></tr>\n";
		}
		
		if(Trim($this->Description)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("002") . "</td></tr>\n";
		}
		
		if(Trim($this->PersonName)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("003") . "</td></tr>\n";
		}
		
		if(Trim($this->eMail)==""){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("004") . "</td></tr>\n";
		} elseif(!eregi("^[a-z0-9._-]+@[a-z0-9._-]+.[a-z]{2,4}$", $this->eMail)){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("012") . "</td></tr>\n";
		}
		
		if((Trim($this->ICQ)!="")&&(!ereg("(^[0-9]+$)", $this->ICQ))){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("011") . "</td></tr>\n";
		}		
		
		if((Trim($this->Phone)!="")&&(!ereg("((^[0-9]+$)|(^\+[0-9]+$))", $this->Phone))){
			$this->errors_count++;
			$this->LastErrors = $this->LastErrors . "<tr><td class=\"submit_error\">" . $Errors->GetError("010") . "</td></tr>\n";
		}
		
		return $this->errors_count;
	}
}
?>